﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using QLKS.Templates;

namespace QLKS.Views
{
    /// <summary>
    /// Interaction logic for frmBackup.xaml
    /// </summary>
    public partial class frmBackup : FormTrans
    {
        System.Windows.Forms.FolderBrowserDialog DestPathBrowser = new System.Windows.Forms.FolderBrowserDialog();
        System.Windows.Forms.FolderBrowserDialog SourcePathBrowser = new System.Windows.Forms.FolderBrowserDialog();
        
        public frmBackup()
        {
            InitializeComponent();
            txtPath.Text = System.Windows.Forms.Application.StartupPath + "\\Data";
        }

        private void btnBrowse_Click(object sender, RoutedEventArgs e)
        {
            SourcePathBrowser.SelectedPath = txtPath.Text;
            if (SourcePathBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtPath.Text = SourcePathBrowser.SelectedPath;
                // Models.CloneOptionsModel.SourcePath = SourcePathBrowser.SelectedPath;
            }
        }

        //Backup

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtPath.Text))
            {
                MessageBox.Show(M_LAN.Equals("V") ? "Chưa chọn đường dẫn sao lưu!" : "Select Output Path, please!", "QLKS", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (!System.IO.Directory.Exists(txtPath.Text))
            {
                MessageBox.Show(M_LAN.Equals("V") ? "Đường dẫn không hợp lệ!" : "Invalid path!", "QLKS", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            frmProgressBar frm = new frmProgressBar();
            frm.SetValue(70);
            frm.Show();
            bool result = Models.DataProviderModel.Backup(txtPath.Text + "\\Backup" + DateTime.Now.ToString("ddMMyyyy") + ".bak");
           
            frm.SetValue(100);
            frm.Close();

            if(result)
                MessageBox.Show(M_LAN.Equals("V")?"Backup thành công":"Backup successful!", "QLKS", MessageBoxButton.OK, MessageBoxImage.Asterisk);
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
